<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Customer_model short summary.
 *
 * Customer_model description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Customer_model extends CI_Model
{
    public $customer_id;
    public $account;
    public $pass;
    public $phone;
    public $email;
    public $addtime;

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    public function inset_customer($customerModel)
    {
        return $this->db->insert('customer',$customerModel);
    }

    public function get_customer_byid($custmoerid)
    {
        return $this->db->select()->from('customer')->where(array('customer_id'=>$custmoerid))->get()->row();
    }

    //登陆
    public function get_login_account($customerModel)
    {
        $sql="select * from customer where account='".$customerModel->account."' or email='".$customerModel->account."' and pass='".$customerModel->pass."'";
        return $this->db->query($sql)->row();
    }
    public function CheckAddAccountName($val)
    {
        $res= $this->db->select()->from('customer')->where(array('account'=>$val))->get()->row();
        if(empty($res))
        {
            return 1;
        }else{
            return 2;
        }
    }

    public function update_customer_d($customerModel)
    {
        $sql="update customer set account='".$customerModel->account."',phone='".$customerModel->phone."',email='".$customerModel->email."' where customer_id=".$customerModel->customer_id;
        return $this->db->query($sql);
    }
    public function update_customer_p($customerModel)
    {
        $sql="update customer set pass='".$customerModel->pass."' where customer_id=".$customerModel->customer_id;
        return $this->db->query($sql);
    }

    public function CheckEditAccountName($val,$cid)
    {
        $sql="select * from customer where account='".$val."' and customer_id<>$cid";

        $res=$this->db->query($sql)->row();// $this->db->select()->from('customer')->where(array('account'=>$val))->get()->result_array();
        //p($res);
        if(empty($res))
        {
            return 1;
        }else{
            return 2;
        }
    }
}